import { MessageBox } from 'element-ui'
import { awaitTimeout, Widget } from 'fdd-contract'

/** 模拟 Ajax 请求 */
export async function mockAjax<T extends () => void>(callback: T): Promise<ReturnType<T>> {
  return awaitTimeout(Math.random() * 1000, callback)
}

/** 控件数据提示 */
export function alertWidgetsRaw(data: Widget[]) {
  MessageBox.alert(
    `<pre class="demo-alert-data">${JSON.stringify(data.map(item => item.getRawField()))}</pre>`,
    '提交数据',
    {
      dangerouslyUseHTMLString: true
    }
  )
}
